<template>
  <view>
    <web-view :src="option.src" @error="webViewError"></web-view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      option: {
        src: "",
      },
    };
  },
  methods: {
    // 访问出错，返回上一页
    webViewError(e) {
      uni.showModal({
        title: "页面出错",
        content: "无法访问当前网站链接,点击返回上一页",
        showCancel: false,
        confirmText: "返回上一页",
        confirmColor: "#23b1d2",
        success: function (res) {
          uni.navigateBack({
            delta: -1,
          });
        },
      });
    },

    // 获取参数
    getOptions(options) {
      let option = options || {
        src: "",
        backbtn: false,
        backbtntext: "返回上一页",
      };
      this.option.src = unescape(this.option.src);
    },
  },
  onLoad(options) {
    try {
      let src = options.src;
      this.option.src = src;
    } catch (err) {
      uni.showToast({
        title: "访问网址参数错误",
        duration: 2000,
        icon: "none",
        mask: false,
        success: (res) => {
          uni.navigateBack({
            delta: -1,
          });
        },
      });
    }
    this.getOptions(options);
  },
};
</script>

<style></style>
